<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>项目</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="app-content-workorder">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">工单号</label>
                    <div class="layui-input-block">
                        <input type="text" name="orderid" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">工单标题</label>
                    <div class="layui-input-block">
                        <input type="text" name="title" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">业务性质</label>
                    <div class="layui-input-block">
                        <input type="text" name="attr" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">受理人</label>
                    <div class="layui-input-block">
                        <input type="text" name="accept" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-order" lay-submit lay-filter="LAY-app-order-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <div style="padding-bottom: 10px;">
                <button class="layui-btn layuiadmin-btn-list" data-type="batchdel">删除</button>
                <button class="layui-btn layuiadmin-btn-list" data-type="add">添加</button>
            </div>
            <table id="LAY-app-project-list" lay-filter="LAY-app-project-list"></table>
            <script type="text/html" id="buttonTpl">
                {{#  if(d.status == '2'){ }}
                <button class="layui-btn layui-btn-normal layui-btn-xs">已完成</button>
                {{#  } else if(d.status == '1'){ }}
                <button class="layui-btn layui-btn-primary layui-btn-xs">进行中</button>
                {{#  } else{ }}
                <button class="layui-btn layui-btn-warm layui-btn-xs">未开始</button>
                {{#  } }}
            </script>
            <script type="text/html" id="LAY-app-project-bar">
                <a class="layui-btn layui-btn-xs" href="#/app/project/issue/project_id={{ d.id }}"><i
                        class="layui-icon layui-icon-list"></i>任务</a>
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i
                        class="layui-icon layui-icon-edit"></i>编辑</a>
            </script>
        </div>
    </div>
</div>

<script src="/static/layui/layui.js"></script>
<script>
    layui.config({
        base: '/static/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'project', 'table'], function(){
        var $ = layui.$
            , admin = layui.admin
            , view = layui.view
            , form = layui.form
            , table = layui.table;

        form.render(null, 'LAY-app-project-list');

        //监听搜索
        form.on('submit(LAY-app-order-search)', function (data) {
            var field = data.field;

            //执行重载
            table.reload('LAY-app-workorder', {
                where: field
            });
        });

        var active = {
            batchdel: function () {
                var checkStatus = table.checkStatus('LAY-app-project-list')
                    , checkData = checkStatus.data; //得到选中的数据

                if (checkData.length === 0) {
                    return layer.msg('请选择数据');
                }

                layer.confirm('确定删除吗？', function (index) {

                    //执行 Ajax 后重载
                    admin.req({
                        url: layui.setter.host + "/project"
                        , data: data.field
                        , type: "delete"
                        , done: function (res) {
                            if (res.code === 0) {
                                layer.msg(res.message, {icon: 6});
                                table.reload('LAY-app-project-list');
                                layer.close(index); //关闭弹层
                            } else {
                                layer.msg(res.message, {icon: 5});
                            }
                        }
                    });
                });
            },
            add: function () {
                admin.popup({
                    title: '添加项目'
                    , area: ['400px', '400px']
                    , id: 'LAY-popup-content-add'
                    , success: function (layero, index) {
                        view(this.id).render('app/project/listform').done(function () {
                            form.render(null, 'LAY-app-project-form');

                            //监听提交
                            form.on('submit(LAY-app-project-form-submit)', function (data) {
                                admin.req({
                                    url: layui.setter.host + "/project"
                                    , data: data.field
                                    , type: "post"
                                    , done: function (res) {
                                        if (res.code === 0) {
                                            layer.msg(res.message, {icon: 6});
                                            table.reload('datatable'); //数据刷新
                                            layer.close(index); //关闭弹层
                                        } else {
                                            layer.msg(res.message, {icon: 5});
                                        }
                                    }
                                });
                            });
                        });
                    }
                });
            }
        };

        $('.layui-btn.layuiadmin-btn-list').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>
</body>
</html>